package com.huang.controller;


import com.huang.bo.UserInfo;
import com.huang.service.crud.ICrudServiceImpl;
import com.huang.service.impl.ICrudService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

/**
 * 接收前端的注册请求
 */
@Controller
public class RegController {

	/**
	 * 处理注册请求
	 */
	@Autowired
	ICrudServiceImpl iCrudService;
	@RequestMapping("/user/reg")
	public void userReg(HttpServletRequest req, HttpServletResponse resp) throws Exception {

		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");

		System.out.println("-------处理注册请求------");

		//1. 接收注册的参数
		String phone = req.getParameter("phone");
		String password = req.getParameter("password");
		System.out.println("phone = " + phone);
		System.out.println("password = " + password);

		//2. 交给业务层去处理
		UserInfo userInfo = new UserInfo();
		userInfo.setPhone(phone);
		userInfo.setPassword(password);
		userInfo.setSex("男");
		iCrudService.add(userInfo);

		//3. 返回注册结果
		resp.getWriter().println("注册成功...");


	}

	@RequestMapping("/send/vcode")
	public String sendVCode(){
		System.out.println("正在发送短信");
		return "";
	}

}
